<!DOCTYPE html>
<html class="reftest-wait">
<head>
  <title>Test for bugs 807728 and 810426</title>
  <script src="utils.js">
  </script>
  <script>
function start()
{
    document.removeEventListener("MozReftestInvalidate", start, false);

    var plugin = document.getElementById("plugin");
    var color = "FF000000";
    var color_count = 0;
    var last_paint_count = 0;
    // Enough paints to test reusing a surface after it has been
    // moved from front to back buffer.
    var final_paint_count = window.mozPaintCount + 10;
    var final_color = "FFFF0000";

    // Using mozPaintCount to track when content has been updated as an
    // indication that the browser has received updates, instead of
    // plugin.getPaintCount() which tracks when the plugin sends updates or
    // MozAfterPaint events which track OS paints.  Not using
    // MozPaintWaitFinished because invalidation causes no geometry changes.
    function wait_for_paints() {
        var paint_count = window.mozPaintCount;
        if (paint_count >= final_paint_count && color == final_color) {
            document.documentElement.removeAttribute("class");
            return;
        }
        if (paint_count != last_paint_count) {
            last_paint_count = paint_count;
            if (paint_count + 1 >= final_paint_count) {
                color = final_color;
                // Wait for the paint with the final color
                final_paint_count = paint_count + 1;
            } else {
                ++color_count;
                color = "FF00000" + color_count;
            }
            plugin.setColor(color);
        }       
        setTimeout(wait_for_paints, 0);
    }

    wait_for_paints();
}

// MozReftestInvalidate is delivered after initial painting has settled.
document.addEventListener("MozReftestInvalidate", start, false);
  </script>
</head>
<body onLoad="forceLoadPlugin('plugin', true)">
  <embed id="plugin" type="application/x-test"
         drawmode="solid" color="FF000000" width="30" height="50">
  </embed>
</body>
</html>
